package random.fox.p2p.ui;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;
import random.fox.p2p.App;
import random.fox.p2p.R;
import random.fox.p2p.event.ActionBarEvent;
import random.fox.p2p.event.ProgressEvent;
import random.fox.p2p.model.LikeModule;
import random.fox.p2p.pathview.HandlesBack;
import random.fox.p2p.presenter.LikePresenter;
import random.fox.p2p.view.ILikeView;

/**
 * Created by wq on 15/3/22.
 */
public class LikeView extends LinearLayout implements ILikeView ,HandlesBack {
    @InjectView(R.id.toolbar)Toolbar toolbar;
    @InjectView(R.id.like_list)RecyclerView recyclerView;

    @Inject
    LikePresenter presenter;

    public LikeView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.inject(this);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(layoutManager);
        ((App) getContext().getApplicationContext()).createScopedGraph(new LikeModule(this)).inject(this);

        toolbar.setTitle("我喜欢的");
        EventBus.getDefault().post(new ActionBarEvent(toolbar,-1,true));
        presenter.loadData(recyclerView);
    }

    @Override
    public void showProgress() {
        EventBus.getDefault().post(new ProgressEvent(true));
    }

    @Override
    public void hideProgress() {
        EventBus.getDefault().post(new ProgressEvent(false));
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public boolean onBackPressed() {
        presenter.releaseData(); //退出当前界面了
        return false;
    }
}
